﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VMC.Processor.Abstract;
using System.IO;

namespace VMC.Processor
{
    public class Processor<T> : IProcessor<T> where T: class
    {
        public Stream DataStream { get; set; }

        public Processor()
        {
            DataStream = null;
        }
        public void Dispose()
        {
            if (DataStream != null)
                DataStream.Close();       
        }

        public virtual void Open(string FilePath)
        {
            if (File.Exists(FilePath))
            {
                DataStream = (Stream)File.Open(FilePath, FileMode.Create,FileAccess.ReadWrite);
            }
        }

        public virtual void OpenReadOnly(string FilePath)
        {
            if(File.Exists(FilePath))
            {
                DataStream = (Stream)File.Open(FilePath, FileMode.Open,FileAccess.Read);
            }
            
        }

        public void Close(string FilePath)
        {
            if (DataStream != null)
                DataStream.Close();
        }

        public virtual T Read() { return null; }
        public virtual List<T> ReadAll() { return null; }
        public virtual void Write(T Object) {  }
        public virtual void Write(List<T> ObjectList) { }

    }
}
